package com.juc.semaphore.semaphore9;

import java.util.concurrent.Semaphore;

public class MyService {
    /**
     * getQueueLength()的作用取得等待许可的线程个数
     * hasQueuedThreads() 判断有没有线程在等待这个
     */
    private Semaphore semaphore =new Semaphore(1);

    public void teseMethod(){
        try {
            semaphore.acquire();
            Thread.sleep(1000);
            System.out.println(" 还有大约 " + semaphore.getQueueLength() + " 个线程在等待");
            System.out.println(" 是否有线程正在等信号呢？" + semaphore.hasQueuedThreads());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
            semaphore.release();
        }
    }
}
